package com.godyao.mall.sms.controller;

import com.godyao.mall.common.to.SkuReductionTo;
import com.godyao.mall.core.model.ResultMsg;
import com.godyao.mall.core.utils.PageUtils;
import com.godyao.mall.sms.entity.SkuFullReductionEntity;
import com.godyao.mall.sms.service.SkuFullReductionService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 商品满减信息
 *
 * @author godyao
 * @email godyao0801@qq.com
 * @date 2022-04-19 15:22:30
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("sms/skufullreduction")
public class SkuFullReductionController {

    private final SkuFullReductionService skuFullReductionService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public ResultMsg list(@RequestParam Map<String, Object> params){
        PageUtils page = skuFullReductionService.queryPage(params);

        return ResultMsg.resultSuccess(page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public ResultMsg info(@PathVariable("id") Long id){
		SkuFullReductionEntity skuFullReduction = skuFullReductionService.getById(id);

        return ResultMsg.resultSuccess(skuFullReduction);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public ResultMsg save(@RequestBody SkuFullReductionEntity skuFullReduction){
		skuFullReductionService.save(skuFullReduction);

        return ResultMsg.resultSuccess("OK");
    }

    @PostMapping("/saveinfo")
    public ResultMsg saveInfo(@RequestBody SkuReductionTo reductionTo){
        skuFullReductionService.saveSkuReduction(reductionTo);
        return ResultMsg.resultSuccess();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public ResultMsg update(@RequestBody SkuFullReductionEntity skuFullReduction){
		skuFullReductionService.updateById(skuFullReduction);

        return ResultMsg.resultSuccess("OK");
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public ResultMsg delete(@RequestBody Long[] ids){
		skuFullReductionService.removeByIds(Arrays.asList(ids));

        return ResultMsg.resultSuccess("OK");
    }

}
